<div ng-controller="MyDetailLockOrderC">
    <div class="modal fade" id="baokuan" tabindex="-1" role="dialog" aria-labelledby="ModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form name="myform" class="form-validation">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title"  id="ModalLabel">新建报款</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="control-label">客户：{{dataLockOrder.Customer.ShortName}}--户头：{{dataLockOrder.Account.Name}}</label>
                        </div>
                        <div class="form-group">
                            <label class="control-label">金额</label>
                            <input required type="number" min="0"  class="form-control" ng-model="NowData.Sum">
                        </div>
                        <div ng-if="dataLockOrder.Account.IsCash" class="form-group">
                            <label class="control-label">备注(必填)</label>
                            <input required type="text" class="form-control" ng-model="NowData.Remark" placeholder="请输入打卡账户后四位">
                        </div>
                        <div ng-if="!dataLockOrder.Account.IsCash" class="form-group">
                            <label class="control-label">备注(选填)</label>
                            <input type="text" class="form-control" ng-model="NowData.Remark" placeholder="请输入打卡账户后四位">
                        </div>
                        <div class="form-group">
                            <label>收款账户</label>
                            <select required class="form-control" ng-model="NowData.ToAccount">
                                <option value="公-交行西苑路支行">公-交行西苑路支行</option>
                                <option value="公-工行洛南支行">公-工行洛南支行</option>
                                <option value="公-洛阳银行洛龙区支行">公-洛阳银行洛龙区支行</option>
                                <option value="公-伊川农商行人民路支行">公-伊川农商行人民路支行</option>
                                <option value="公-北京沐威中行">公-北京沐威中行</option>
                                <option value="中国农业银行洛阳中泓支行">中国农业银行洛阳中泓支行</option>
                                <option value="中国工商银行洛阳政和支行">中国工商银行洛阳政和支行</option>
                                <option value="中国建设银行洛阳开元大道支行">中国建设银行洛阳开元大道支行</option>
                                <option value="中国银行洛阳政和路支行">中国银行洛阳政和路支行</option>
                                <option value="交通银行洛阳分行营业部">交通银行洛阳分行营业部</option>
                                <option value="洛阳农商行金城寨街支行">洛阳农商行金城寨街支行</option>
                                <option value="中信银行洛阳联盟路支行">中信银行洛阳联盟路支行</option>
                                <option value="兴业银行洛阳凯旋东路支行">兴业银行洛阳凯旋东路支行</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label class="control-label">付款时间</label>
                            <input required type="datetime-local" class="form-control" ng-model="NowData.CreateTime">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success" ng-disabled="myform.$invalid" ng-click="add()">确认报备</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">锁价单详情</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="form-group">
                                <label>客户信息</label>
                                <input type="text" class="form-control" readonly="readonly" value="{{dataLockOrder.Customer.ShortName}}--{{dataLockOrder.Customer.ShortName}}">
                            </div>
                            <div class="form-group">
                                <label>户头</label>
                                <input type="text" class="form-control" readonly="readonly" value="{{dataLockOrder.Account.Name}}">
                            </div>
                            <div class="form-group">
                                <label>仓库</label>
                                <input type="text" class="form-control" readonly="readonly" value="{{dataLockOrder.Provider.Name}}">
                            </div>
                            <!--<div class="form-group">-->
                                <!--<label style="margin-right: 10px;">是否标件</label>-->
                                <!--<label class="i-switch bg-info">-->
                                    <!--<input type="checkbox" disabled="disabled" ng-model="dataLockOrder.IsStandard">-->
                                    <!--<i></i>-->
                                <!--</label>-->
                            <!--</div>-->
                            <div class="form-group">
                                <label style="margin-right: 10px;">是否标件:</label>
                                <!--<label class="i-switch bg-info">-->
                                <!--<input type="checkbox" disabled="disabled" ng-model="dataLockOrder.IsStandard">-->
                                <!--<i></i>-->
                                <!--</label>-->
                                <span ng-if="dataLockOrder.IsStandard">标件</span>
                                <span ng-if="!dataLockOrder.IsStandard">非标件</span>
                            </div>
                            <div class="form-group">
                                <label>订单类型：</label>
                                <label ng-if="dataLockOrder.OrderType == 0">普通订单</label>
                                <label ng-if="dataLockOrder.OrderType == 1">商品锁价</label>
                                <label ng-if="dataLockOrder.OrderType == 2">基价锁价</label>
                                <label ng-if="dataLockOrder.OrderType == 3">自采订单</label>
                            </div>
                            <div class="form-group">
                                <label>锁价金额：</label>
                                <label>{{dataLockOrder.Total | number:2}}</label>
                            </div>
                            <div class="form-group">
                                <label>每吨优惠合计：</label>
                                <label>{{dataLockOrder.UnitDiscount | number:2}}</label>
                            </div>
                            <div class="form-group">
                                <label>申请单价优惠：</label>
                                <label>{{dataLockOrder.ApplyDiscount | number:2}}</label>
                            </div>
                            <div class="form-group">
                                <label>商品列表：</label>
                                <ul>
                                    <li>
                                        <label>名称</label>
                                        <label>材质</label>
                                        <label>规格</label>
                                        <label>/件重/</label>
                                        <label>[价格]</label><br>
                                    </li>
                                    <li ng-repeat="item in dataLockOrder.DepotCommodityRecords">
                                        <label>{{item.Commodity.Name}}</label>
                                        <label>{{item.Commodity.Standard}}</label>
                                        <label>{{item.Commodity.Format}}</label>
                                        <label>/{{item.Commodity.Weight}}/</label>
                                        <label>[{{item.Price | number:2}}]</label><br>
                                    </li>
                                </ul>
                            </div>
                            <div class="form-group">
                                <label>相关订单（创建时间/编号/总金额/状态）</label>
                                <ul>
                                    <li ng-repeat="item in dataLockOrder.Orders | orderBy:['CreateTime']">
                                        {{item.CreateTime}}/{{item.CodeNum}}/{{item.Total | number:2}}/
                                        <label ng-if="item.State == 0">待确认</label>
                                        <label ng-if="item.State == 1">驻厂确认</label>
                                        <label ng-if="item.State == 2">已发货</label>
                                        <label ng-if="item.State == 3">已收货</label>
                                        <label ng-if="item.State == 4||item.IsSettlement">已结算</label>
                                        <label ng-if="item.State == 5">完结</label>
                                        <label ng-if="item.State == 6">取消</label>
                                        <label ng-if="item.State == 7">审核通过</label>
                                        <label ng-if="item.State == 8">已退货</label>
                                        <label ng-if="item.State == 9">已退款</label>
                                    </li>
                                </ul>
                            </div>
                            <div class="form-group">
                                <accordion close-others="oneAtATime">
                                    <accordion-group heading="查看历史记录➤">
                                        <ul>
                                            <li ng-repeat="item in dataLockOrder.Records | orderBy:['CreateTime']">
                                                {{item.CreateTime}}/<label ng-if="item.Price != 0">{{item.Price | number:2}}/</label>{{item.Remarks}}
                                            </li>
                                        </ul>
                                    </accordion-group>
                                </accordion>
                            </div>
                            <!--<div class="form-group" ng-if="dataLockOrder.IsApproval">
                                <label style="margin-right: 10px;">审批中</label>
                            </div>
                            <div class="form-group" ng-if="dataLockOrder.IsPause">
                                <label style="margin-right: 10px;">已暂停</label>
                            </div>-->
                            <div class="form-group">
                                <label>状态：</label>
                                <label ng-if="dataLockOrder.IsPause">已暂停</label>
                                <label ng-if="dataLockOrder.IsApproval">审批中</label>
                                <span ng-if="!dataLockOrder.IsApproval&&!dataLockOrder.IsPause">
                                    <label ng-if="dataLockOrder.ProcessState == 0">正常</label>
                                    <label ng-if="dataLockOrder.ProcessState == 1">议价</label>
                                    <label ng-if="dataLockOrder.ProcessState == 2">锁价</label>
                                    <label ng-if="dataLockOrder.ProcessState == 3">款项确认</label>
                                    <label ng-if="dataLockOrder.ProcessState == 4">完结</label>/
                                    <label ng-if="dataLockOrder.State == 0">待确认</label>
                                    <label ng-if="dataLockOrder.State == 1">驻厂确认</label>
                                    <label ng-if="dataLockOrder.State == 2">已发货</label>
                                    <label ng-if="dataLockOrder.State == 3">已收货</label>
                                    <label ng-if="dataLockOrder.State == 4">已结算</label>
                                    <label ng-if="dataLockOrder.State == 5">完结</label>
                                    <label ng-if="dataLockOrder.State == 6">取消</label>
                                    <label ng-if="dataLockOrder.State == 7">审核通过</label>
                                    <label ng-if="dataLockOrder.State == 8">已退货</label>
                                    <label ng-if="dataLockOrder.State == 9">已退款</label>
                                </span>
                            </div>
                            <div class="form-group" ng-if="(dataLockOrder.ProcessState == 3 || dataLockOrder.IsPause||dataLockOrder.ProcessState==2)&&dataLockOrder.State!=6">
                                <button type="button" class="btn btn-success" data-toggle="modal" data-target="#baokuan">新建报款</button>
                            </div>
                        </div>
                        <div class="container-fluid">
                            <div class="row" style="border-bottom: red solid 1px" ng-repeat="item in orderdetaildata.CommodityInfos">
                                <div class="col-xs-12 col-md-12">
                                    <div>钢厂：{{item.ProviderCommodity.Commodity.Brand}}</div>
                                    <div>名称/材质/规格：{{item.ProviderCommodity.Commodity.Name}}/{{item.ProviderCommodity.Commodity.Standard}}/{{item.ProviderCommodity.Commodity.Format}}</div>
                                    <div>单价：{{item.Price | number:2}}/t</div>
                                    <div>数量：{{item.Count}}</div>
                                    <div>总质量：{{item.ProviderCommodity.Commodity.Weight | number:3}}t</div>
                                    <div>总价：{{item.Price | number:2}}*{{item.ProviderCommodity.Commodity.Weight | number:3}}t={{item.Price*item.ProviderCommodity.Commodity.Weight | number:2}}</div>
                                </div>
                            </div>
                            <div class="row text-right">
                                <button type="button" class="btn btn-success" ng-if="dataLockOrder.State == 7&&!dataLockOrder.IsApproval " ng-disabled="zongshu>=(dataLockOrder.Total*1.1)" ng-click="changeOrder()">转为计划单</button>
                                <!--<button type="button" class="btn btn-warning" ng-if="dataLockOrder.State != 0" ng-click="suspend()">暂停</button>-->
                                <button type="button" class="btn btn-danger" ng-if="(dataLockOrder.State == 7&&!dataLockOrder.IsApproval) || (dataLockOrder.State == 9 && (dataLockOrder.Total>dataLockOrder.Refund)) " ng-click="cancel()">退款</button>
                                <!--<button type="button" class="btn" ng-if="dataLockOrder.State = 0" ng-click="cancel()">取消</button>-->
                                <button type="button" class="btn btn-default" ng-click="abolish()">返回</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app')  //编辑员工控制器
    .controller("MyDetailLockOrderC", function ($scope, $state, $stateParams, $http) {
        $scope.NowData = {
            Customer:{},
            AccountId:"",
            CreateTime: new Date(new Date().format("yyyy-MM-dd hh:mm:ss"))
        };
        $scope.zongshu = 0;
        $scope.orderiddetail = JSON.parse($stateParams.orderid);
        //获取员工数据方法
        $scope.refresh = function(){
            $http({
                url: "../api/LockOrder/Detail?id=" + $scope.orderiddetail,
                method:"GET"
            })
                    .then(function (res) {
                        $scope.dataLockOrder = res.data;
                        for(var i = 0; i < $scope.dataLockOrder.Orders.length; i++){
                            if ($scope.dataLockOrder.Orders[i].State==9||$scope.dataLockOrder.Orders[i].State==6) {
                                $scope.dataLockOrder.Orders[i].Total=(-$scope.dataLockOrder.Orders[i].Total)
                            }   
                            $scope.zongshu += $scope.dataLockOrder.Orders[i].Total
                        }
                        console.log($scope.dataLockOrder);
                    })
                    .then(function (error) {
                        if(error){
                            console.log("error");
                        }
                    });
        };
//        获取数据
        $scope.refresh();

        //转为计划单
        $scope.changeOrder = function(){
            $state.go('app.LockOrder_LockToOrder', {
                orderid: JSON.stringify($scope.orderiddetail)
            });
        };
        //返回上一页
        $scope.abolish = function(){
            $state.go('app.MyLockOrder_List');
        };
        //暂停
        $scope.suspend = function(){
            $http({
                url: "../api/LockOrder/IsPause?id=" + $scope.dataLockOrder.Id,
                method:"POST"
            })
                    .then(function (res) {
                        alert("订单已暂停");
                        $scope.refresh();
                    })
                    .then(function (error) {
                        if(error){
                            console.log("error");
                        }
                    });
        };
        //退款
        $scope.cancel = function () {
            $http({
                url: "../api/LockOrder/Refund?id=" + $scope.dataLockOrder.Id,
                method:"POST"
            })
                    .then(function (res) {
                        alert(res.data.Msg);
                        console.log(res.data.Msg);
                        $scope.refresh();
                    })
                    .then(function (error) {
                        if(error){
                            console.log("error");
                        }
                    });
        };
        $scope.add = function () {
            $scope.NowData.Customer.ShortName = $scope.dataLockOrder.Customer.ShortName;
            $scope.NowData.AccountId = $scope.dataLockOrder.Account.Id;
            console.log($scope.NowData.CreateTime);
            $http.post("/api/ClientManager/ApplyPaymentInfo", $scope.NowData)
                    .then(function (res) {
                        if (res.State <= 0) {
                            alert(res.Msg);
                        } else {
                            alert("提交成功");
                            $('#baokuan').modal("hide");
                        }

                    },function (error) {
                        if (error) {
                            alert("失败");
                        }
                    });
        };

    })
</script>